package cn.chinasyq.photoquan.photo;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.photo.fragment.GamePhotoSearchListFragment;

/**
 * Created by 一搏 on 2015/11/24.
 */
public class PhotoSearchActivity extends FragmentActivity implements TextView.OnEditorActionListener, View.OnClickListener {
    private ImageButton ibtn_del;
    private String keyword;
    private EditText et_search;
    private Button btn_cancle;
    private GamePhotoSearchListFragment f;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search_news);
        ibtn_del = (ImageButton) findViewById(R.id.ibtn_del);
        ibtn_del.setOnClickListener(this);
        btn_cancle = (Button) findViewById(R.id.btn_cancle);
        btn_cancle.setOnClickListener(this);
        et_search = (EditText) findViewById(R.id.et_search);
        et_search.setOnEditorActionListener(this);
        f = (GamePhotoSearchListFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    }


    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            keyword = v.getText().toString();
            f.search(keyword);
        }

        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_cancle:
                onBackPressed();
                break;
            case R.id.ibtn_del:
                et_search.setText("");
                break;
        }
    }
}
